//逻辑业务维护
export default function (state) {
  const onAddTodo = (todo) => {
    return {
      ...state,
      todoList: [...state.todoList, todo],
      addCount: state.addCount + 1
    }
  };

  const onToggleTodo = (id) => {
    const todoList = state.todoList.map((item) => {
      item.id === id && (item.completed = !item.completed);
      return item;
    });

    return {
      ...state,
      todoList
    }
  };

  const onRemoveTodo = (id) => {
    const todoList = state.todoList.filter((item) => item.id !== id);

    return {
      ...state,
      todoList,
      removeCount: state.removeCount + 1
    }
  };

  return {
    onAddTodo,
    onToggleTodo,
    onRemoveTodo
  }
}